// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Vant from 'vant';
import 'vant/lib/index.css';
import store from './store'

import {get, post} from './components/Common/http';

Vue.prototype.$get = get;
Vue.prototype.$post = post;
Vue.prototype.$store = store;
Vue.use(Vant);
Vue.config.productionTip = false
router.beforeEach((to, from, next) => {
  document.title = `${to.meta.title} - 后台管理`
  console.log(store.state.isLogin, store.state.admin);
  if (to.matched.some(m => m.meta.auth)) {

// 对路由进行验证
    if (store.state.isLogin) { // 已经登陆
      next()   // 正常跳转到你设置好的页面
    }
    else {

// 未登录则跳转到登陆界面，query:{ Rurl: to.fullPath}表示把当前路由信息传递过去方便登录后跳转回来；

      next({path: '/yycadmin/login', query: {redirect: to.fullPath}})
    }
  } else {
    next()
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {App},
  template: '<App/>'
})
